home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------------------
-
- AppIcon handler, ©1998 Dietmar Eilert
-
- DICE:
-
- dcc app.c appiconA.a -// -proto -mRR -mi -pr -3.0 -o appicon
-
- SAS/C:
-
- sc app.c
-
- CONTENTS
-
- This is a simple AppIcon handler. It will show an application icon (we use the
- editor's default appicon from etc/images/workbench/appicon) on the workbench
- screen. Icons of text files may be dragged and dropped over this icon and the
- editor will load them into a new window. Doubleclick at the icon to have it
- removed.
-
- HOW TO SET THE DEFAULT ICON POSITION ...
-
- Open the etc/images/workbench drawer and move the icon to the preferred
- position, snapshot it (workbench/icon menu). and move the icon back to its
- drawer. The appicon handler will read the new position the next time it is
- evoked.
-
- ------------------------------------------------------------------------------
- */
-
- /// "compiler"
-
- #ifdef __SASC
-
- #define __USE_SYSBASE
- #define __geta4 __saveds
- #define __stkargs __stdargs
-
- #define __A0 register __a0
- #define __A1 register __a1
- #define __A2 register __a2
- #define __A3 register __a3
- #define __A4 register __a4
- #define __A5 register __a5
- #define __A6 register __a6
- #define __A7 register __a7
- #define __D0 register __d0
- #define __D1 register __d1
- #define __D2 register __d2
- #define __D3 register __d3
- #define __D4 register __d4
- #define __D5 register __d5
- #define __D6 register __d6
- #define __D7 register __d7
-
- #endif
-
- #ifdef _DCC
-
- #define __asm
-
- #endif
-
- ///
- /// "includes"
-
- #include <exec/exec.h>
- #include <string.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <intuition/intuition.h>
- #include <dos/dos.h>
- #include <dos/dosextens.h>
- #include <dos/rdargs.h>
- #include <dos/dostags.h>
- #include <workbench/startup.h>
- #include <workbench/workbench.h>
- #include <rexx/errors.h>
- #include <rexx/rxslib.h>
-
- // prototypes
-
- #include <clib/alib_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/icon_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/utility_protos.h>
- #include <clib/rexxsyslib_protos.h>
- #include <clib/wb_protos.h>
-
- // pragmas
-
- #ifdef __SASC
-
- #include <pragmas/rexxsyslib_pragmas.h>
- #include <pragmas/utility_pragmas.h>
- #include <pragmas/wb_pragmas.h>
- #include <pragmas/dos_pragmas.h>
- #include <pragmas/icon_pragmas.h>
- #include <pragmas/intuition_pragmas.h>
- #include <pragmas/exec_sysbase_pragmas.h>
-
- #endif
-
- ///
- /// "globals"
-
- #ifdef __SASC
-
- UBYTE Version[] = "$VER: appicon 3.2 " __AMIGADATE__ "\n\0";
-
- #endif
-
- #ifdef _DCC
-
- UBYTE Version[] = "$VER: appicon 3.2 (" __COMMODORE_DATE__ ")\n\0";
-
- #endif
-
- extern struct Library *IconBase;
- extern struct Library *DOSBase;
- extern struct Library *SysBase;
- extern struct Library *IntuitionBase;
- extern struct Library *WorkbenchBase;
- extern struct Library *RexxSysBase;
-
- ///
- /// "defines"
-
- #define Prototype extern
- #define MAX_PATHLEN 512
-
- ///
- /// "prototypes"
-
- Prototype int main(ULONG, char **);
- Prototype int wbmain(struct WBStartup *);
- Prototype int MainLoop(void);
- Prototype UBYTE *MakeFileName (UBYTE *, UBYTE *);
- Prototype UBYTE *CompletePath(UBYTE *);
- Prototype UBYTE *StartGED(void);
- Prototype struct RexxMsg *SendRexxCommand(UBYTE *, UBYTE *, struct MsgPort *);
- Prototype void FreeRexxCommand (struct RexxMsg *);
- Prototype ULONG WaitForAnswer(struct MsgPort *);
- Prototype UBYTE *LookForGED(void);
- Prototype void ReadWBCmd(ULONG, struct WBArg *);
-
- ///
- /// "entry points"
-
- int
- main(argc, argv)
-
- ULONG argc;
- char *argv[];
- {
- return(MainLoop());
- }
-
- int
- wbmain(struct WBStartup *wbs)
- {
- return(MainLoop());
- }
-
-
- ///
- /// "main loop"
-
- /* --------------------------------- MainLoop ----------------------------------
-
- Open AppIcon, handle incoming messages
-
- */
-
- int
- MainLoop()
- {
- struct DiskObject *appDiskObject;
- int error;
-
- error = 0;
-
- appDiskObject = GetDiskObject("golded:etc/images/wb/appicon");
-
- if (appDiskObject == NULL)
-
- appDiskObject = GetDefDiskObject(WBTOOL);
-
- if (appDiskObject) {
-
- struct MsgPort *msgPort;
- struct AppMessage *amsg;
- struct AppIcon *appIcon;
-
- if (msgPort = CreateMsgPort()) {
-
- if (appIcon = AddAppIconA(0, NULL, "GoldED", msgPort, NULL, appDiskObject, TAG_END)) {
-
- BOOL terminated = FALSE;
-
- while (terminated == FALSE) {
-
- while (amsg = (struct AppMessage *)GetMsg(msgPort)) {
-
- if (amsg->am_NumArgs)
- ReadWBCmd(amsg->am_NumArgs, amsg->am_ArgList);
- else
- terminated = TRUE;
-
- ReplyMsg((struct Message *)amsg);
- }
-
- WaitPort(msgPort);
- }
- }
- else {
-
- error = 20;
-
- puts("Couldn't allocate AppIcon. Workbench closed ?!");
- }
-
- RemoveAppIcon(appIcon);
-
- DeleteMsgPort(msgPort);
- }
- else {
-
- error = 20;
-
- puts("Couldn't create message port ?!");
- }
-
- FreeDiskObject(appDiskObject);
- }
- else {
-
- error = 20;
-
- puts("Error reading icon");
- }
-
- return(error);
- }
-
-
- ///
- /// "misc"
-
- /* ------------------------------- MakeFileName --------------------------------
-
- Build fully qualified path from file/path names; return pointer to static copy.
-
- */
-
- UBYTE *
- MakeFileName(path, file)
-
- UBYTE *path, *file;
- {
- static UBYTE buffer[MAX_PATHLEN];
-
- strcpy(buffer, "\42");
-
- strcat(buffer, path);
-
- CompletePath(buffer);
-
- strcat(buffer, file);
-
- strcat(buffer, "\42");
-
- return(buffer);
- }
-
- /* ------------------------------ CompletePath -----------------------------------
-
- Add '/' to path if missing so far
-
- */
-
- UBYTE *
- CompletePath(path)
-
- UBYTE *path;
- {
- UWORD len;
-
- if (len = strlen(path))
-
- if ((path[len - 1] != ':') && (path[len - 1] != '/'))
-
- strcat(path, "/");
-
- return(path);
- }
-
- /* ---------------------------------- ReadWBCmd --------------------------------
-
- Parse AppIcon message
-
- */
-
- void
- ReadWBCmd(numArgs, argList)
-
- ULONG numArgs;
- struct WBArg *argList;
- {
- UBYTE *host;
-
- Forbid();
-
- host = LookForGED();
-
- Permit();
-
- if (host == NULL)
-
- host = StartGED();
-
- if (host) {
-
- struct MsgPort *replyPort;
-
- if (replyPort = CreateMsgPort()) {
-
- if (SendRexxCommand(host, "LOCK CURRENT RELEASE=4", replyPort)) {
-
- if (WaitForAnswer(replyPort) == RC_OK) {
-
- UBYTE path[MAX_PATHLEN];
-
- UWORD count;
- UBYTE *command;
-
- for (count = 0; numArgs--; count++) {
-
- NameFromLock(argList[count].wa_Lock, path, sizeof(path));
-
- command = MakeFileName(path, argList[count].wa_Name);
-
- strins(command, "OPEN SMART QUIET ");
-
- if (SendRexxCommand(host, command, replyPort))
-
- WaitForAnswer(replyPort);
- }
- }
-
- if (SendRexxCommand(host, "UNLOCK", replyPort))
-
- WaitForAnswer(replyPort);
- }
-
- DeleteMsgPort(replyPort);
- }
- }
- }
-
-
- /* ----------------------------------- LookForGED ----------------------------
-
- Look for running editor task
-
- */
-
- UBYTE *
- LookForGED()
- {
- static UBYTE host[] = "GOLDED.1";
-
- UWORD try;
-
- for (try = '1'; try <= '9'; try++) {
-
- host[7] = try;
-
- if (FindPort(host))
-
- return(host);
- }
-
- return(NULL);
- }
-
-
- /* ------------------------------------- StartGED -----------------------------
-
- Launch a new editor task. Return pointer to host name (or NULL).
-
- */
-
- UBYTE *
- StartGED()
- {
- struct MsgPort *port = NULL;
-
- if (SystemTags("golded:golded", SYS_Asynch, TRUE, SYS_Input, NULL, SYS_Output, NULL, TAG_DONE) == 0) {
-
- UWORD try;
-
- for (try = 50; try; (port == NULL) && try--, Delay(10)) {
-
- Forbid();
-
- port = FindPort("GOLDED.1");
-
- Permit();
- }
- }
-
- return((port) ? "GOLDED.1" : NULL);
- }
-
- ///
- /// "ARexx"
-
- /* -------------------------------------- WaitForAnswer -----------------------
-
- Wait for answer on previously sent message. Free message afterwards. Primary
- return code is returned.
-
- */
-
- ULONG
- WaitForAnswer(port)
-
- struct MsgPort *port;
- {
- struct RexxMsg *rexxMsg;
- ULONG result;
-
- result = 0;
-
- do {
-
- WaitPort(port);
-
- if (rexxMsg = (struct RexxMsg *)GetMsg(port))
-
- result = rexxMsg->rm_Result1;
-
- } while (!rexxMsg);
-
- FreeRexxCommand(rexxMsg);
-
- return(result);
- }
-
-
- /* ------------------------------------- FreeRexxCommand ----------------------
-
- Free ARexx message
-
- */
-
- void
- FreeRexxCommand(rexxmessage)
-
- struct RexxMsg *rexxmessage;
- {
- if (rexxmessage->rm_Result1 == RC_OK)
-
- if (rexxmessage->rm_Result2)
-
- DeleteArgstring((char *)rexxmessage->rm_Result2);
-
- DeleteArgstring((char *)ARG0(rexxmessage));
-
- DeleteRexxMsg(rexxmessage);
- }
-
-
- /* ---------------------------------- SendRexxCommand -------------------------
-
- Send ARexx message
-
- */
-
- struct RexxMsg *
- SendRexxCommand(port, cmd, replyPort)
-
- struct MsgPort *replyPort;
- UBYTE *cmd, *port;
- {
- struct MsgPort *rexxport;
- struct RexxMsg *rexx_command_message = NULL;
-
- Forbid();
-
- if (rexxport = FindPort(port)) {
-
- if (rexx_command_message = CreateRexxMsg(replyPort, NULL, NULL)) {
-
- if (rexx_command_message->rm_Args[0] = CreateArgstring(cmd, strlen(cmd))) {
-
- rexx_command_message->rm_Action = RXCOMM | RXFF_RESULT;
-
- PutMsg(rexxport, &rexx_command_message->rm_Node);
- }
- }
- }
-
- Permit();
-
- return(rexx_command_message);
- }
-
- ///
-